package pers.wwz.study.shardingjdbc.config;

import com.google.common.collect.Range;

import org.apache.shardingsphere.api.sharding.standard.RangeShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.RangeShardingValue;

import java.util.Collection;

public class ModRangeShardingAlgorithm implements RangeShardingAlgorithm<Long> {

    @Override
    public Collection<String> doSharding(Collection<String> availableTargetNames, RangeShardingValue<Long> shardingValue) {
        Range valueRange = shardingValue.getValueRange();

        //无边界 正负无穷
        if(!valueRange.hasLowerBound() || !valueRange.hasUpperBound()) {
            return availableTargetNames;
        }
        Long smallVal = (Long)valueRange.lowerEndpoint();
        Long bigVal = (Long) valueRange.upperEndpoint();

        // do something
        
        return availableTargetNames;
    }
}
